<template>
  <div style="height: 800px; overflow: auto">
    <a-card>
      <Alert message="基本信息" type="info" show-icon style="margin-bottom: 20px" />
      <SchemaForm @submit="handleSubmit"> </SchemaForm>

      <Alert message="监测属性" type="success" show-icon style="margin: 20px 0" />
      <monitoringAttributeForm ref="monitoringAttributeFormRef"></monitoringAttributeForm>

      <Alert message="设备参数" type="success" show-icon style="margin: 20px 0" />
      <equipmentParametersForm ref="equipmentParametersFormRef"></equipmentParametersForm>

      <Alert message="设备控制" type="warning" show-icon style="margin: 20px 0" />
      <controlForm ref="controlFormRef"></controlForm>
    </a-card>
  </div>
</template>
<script lang="tsx" setup>
  import { ref } from 'vue';
  import { Alert, message } from 'ant-design-vue';
  import { manageSchemas } from './formSchemas';
  import monitoringAttributeForm from './monitoringAttribute/index.vue';
  import equipmentParametersForm from './equipmentParameters/index.vue';
  import controlForm from './control/index.vue';
  import { useForm } from '@/components/core/schema-form';
  import { createManage } from '@/api/model/manage';
  defineOptions({
    name: 'ManageForm',
  });
  defineExpose({
    saveData,
  });
  const [SchemaForm, dynamicFormRef] = useForm({
    labelWidth: 140,
    schemas: manageSchemas,
    actionColOptions: {
      span: 24,
    },
    showActionButtonGroup: false,
  });

  const handleSubmit = (values: any) => {
    message.success(`click search,values:${JSON.stringify(values)}`);
  };

  const monitoringAttributeFormRef = ref(null);
  const equipmentParametersFormRef = ref(null);
  const controlFormRef = ref(null);

  async function saveData() {
    console.log();
    // dynamicFormRef
    //   .validate()
    //   .then(() => {
    //
    //   })
    //   .catch((error) => {
    //     message.error(`校验不通过`);
    //     //return Promise.reject(error);
    //   });
    const model = dynamicFormRef.getFieldsValue();
    model.monitoringAttribute = monitoringAttributeFormRef.value.dataSource;
    model.equipmentParameters = equipmentParametersFormRef.value.dataSource;
    model.control = controlFormRef.value.dataSource;
    await createManage(model);
  }
</script>
